<?php

namespace App\Service\UserCenter\v1_0_8;

use App\Constants\ErrorCode;
use App\Model\UserProfilePersonal;
use App\Model\WithdrawAccountLog;
use App\Service\BaseService;

/**
 * 绑定提现收款账号
 */
class WithdrawBindService extends BaseService
{
    protected function RoVerifyList()
    {
        return [
            'account_type' => 'required|int',
            'account' => 'required|string',
        ];
    }

    public function handle()
    {
        $userId = $this->getUserId();
        //绑定方式：0-支付宝，1-银行卡
        $accountType  = $this->request->input('account_type', 0);
        // if ($accountType == 1) {
        //     return $this->setError(ErrorCode::PARAMETER_ERROR, '暂不支持银行卡绑定，请绑定支付宝～');
        // }
        $account = $this->request->input('account', '');
        $info = [];
        switch ($accountType) {
                //支付宝
            case 0:
                $info['alipay_account'] = $account;
                break;
                //银行卡
            case 1:
                $info['bank_card'] = $account;
                break;
        }
        //更新收款资料
        UserProfilePersonal::updateInfo($userId, $info);
        //添加日志
        WithdrawAccountLog::addRecord($userId, 1, $account, $accountType);
        $ret = ['result' => 1];
        log_user_result($userId, $ret);
        return $ret;
    }
}
